package HDFS;

import java.util.List;

public class HdfsFileTest {
    public static void main(String[] args) {
//change the path to your hadoop install path
        System.setProperty("hadoop.home.dir","C:/Program Files/hadoop-2.8.3" );
        try {
            List<String> dirs = HdfsUtils.listAll(HdfsUtils.getCompleteDirOfHDFS("/"));
            HdfsUtils.createNewHDFSFile(HdfsUtils.getCompleteDirOfHDFS("/newFile.txt"), "There is never too old to learn!");
            for (String dir : dirs) {
                System.err.println(dir);
            }
            System.err.println("\n");
            HdfsUtils.downloadHDFS2LocalFile(HdfsUtils.getCompleteDirOfHDFS("/newFile.txt"), "C:/Users/1/Downloads");
            dirs = HdfsUtils.listAll(HdfsUtils.getCompleteDirOfHDFS("/"));
            for (String dir : dirs) {
                System.err.println(dir);
            }
            System.err.println("\n");
            HdfsUtils.uploadLocalFile2HDFS("C:/Users/1/Downloads/despacito.lyric", HdfsUtils.getCompleteDirOfHDFS("/"));
            dirs = HdfsUtils.listAll(HdfsUtils.getCompleteDirOfHDFS("/"));
            for (String dir : dirs) {
                System.err.println(dir);
            }
            System.err.println("\n");
            HdfsUtils.deleteHDFSFile(HdfsUtils.getCompleteDirOfHDFS("/newFile.txt"));
            dirs = HdfsUtils.listAll(HdfsUtils.getCompleteDirOfHDFS("/"));
            for (String dir : dirs) {
                System.err.println(dir);
            }
            System.err.println("\n");
            HdfsUtils.append(HdfsUtils.getCompleteDirOfHDFS("/test.txt"), "\nedit by Murphy!");
            dirs = HdfsUtils.listAll(HdfsUtils.getCompleteDirOfHDFS("/"));
            for (String dir : dirs) {
                System.err.println(dir);
            }
            System.err.println("\n");
            HdfsUtils.rename(HdfsUtils.getCompleteDirOfHDFS("/test.txt"), HdfsUtils.getCompleteDirOfHDFS("/script.txt"));
            dirs = HdfsUtils.listAll(HdfsUtils.getCompleteDirOfHDFS("/"));
            for (String dir : dirs) {
                System.err.println(dir);
            }
            System.err.println("\n");
            byte[] bytes = HdfsUtils.readHDFSFile(HdfsUtils.getCompleteDirOfHDFS("/script.txt"));
            String script = new String(bytes);
            System.err.println(script);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
